home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / pmake / command.mk < prev    next >
Text File  |  1992-05-18  |  12KB  |  440 lines

  1. #
  2. # Makefile for commands.  This is a library Makefile that is included
  3. # by the Makefile's for individual commands.  The file that includes
  4. # this one should already have defined the following variables:
  5. #    NAME        name of program to be created
  6. #    SRCS        all source files, used for linting and making
  7. #            dependencies
  8. #    OBJS        object files from which to create it
  9. #    CLEANOBJS    object files to be removed as part of "make clean"
  10. #            (need not just be object files)
  11. #    TM        target machine type for object files etc.
  12. #    MACHINES    list of all target machines currently available
  13. #            for this program
  14. #    TYPE        a keyword identifying which sort of command this
  15. #            is;  used to determine where to install, etc.
  16. #
  17. # Optional variables that may be defined by the invoker:
  18. #    XAFLAGS        additional flags to pass to assembler
  19. #    XCFLAGS        additional flags to pass to linker
  20. #    DEPFLAGS    additional flags to pass to makedepend
  21. #    no_targets    if defined, this file will not define all of the
  22. #            basic targets (make, make clean, etc.)
  23. #    use_version    if defined, then this file will set things up
  24. #            to include a version number that is automatically
  25. #            incremented
  26. #
  27. # $Header: /sprite/lib/pmake/RCS/command.mk,v 1.68 92/04/13 18:33:52 elm Exp Locker: mottsmth $
  28. #
  29.  
  30. #
  31. # The variables below should be defined in md.mk, but they are given
  32. # default values just in case md.mk doesn't exist yet.
  33. #
  34. HDRS        ?=
  35. OBJS        ?=
  36. SRCS        ?=
  37.  
  38. #
  39. # First define search paths for libraries, include files, lint libraries,
  40. # and even sources.
  41. #
  42. .PATH.h        :
  43. .PATH.h        : $(TM).md . /sprite/lib/include /sprite/lib/include/$(TM).md
  44. .PATH.ln    : /sprite/lib/lint
  45. .PATH.c        :
  46. .PATH.c        : $(TM).md
  47. .PATH.s        :
  48. .PATH.s        : $(TM).md
  49.  
  50. #
  51. # Suffix for profiled targets.
  52. #
  53. PROFSUFFIX    ?= .pg
  54.  
  55. #
  56. # Important directories. 
  57. #
  58. MISCLIBDIR    ?= /sprite/lib/misc
  59. BINDIR        ?= /sprite/cmds.$(MACHINE)
  60.  
  61. #
  62. # System programs -- assign conditionally so they may be redefined in
  63. # including makefile.  These need to be defined absolutely so that we
  64. # can remake these programs without flakey new versions accidentally
  65. # getting used to make themselves
  66. #
  67. AS        ?= $(BINDIR)/as
  68. CC        ?= $(BINDIR)/cc
  69. CPLUSPLUS    ?= $(BINDIR)/g++
  70. CP        ?= $(BINDIR)/cp
  71. CPP        ?= $(BINDIR)/cpp -traditional -$
  72. CTAGS        ?= $(BINDIR)/ctags
  73. ETAGS        ?= /emacs/cmds/etags
  74. ECHO        ?= $(BINDIR)/echo
  75. LINT        ?= $(BINDIR)/lint
  76. MAKEDEPEND    ?= $(BINDIR)/makedepend
  77. MKVERSION    ?= $(BINDIR)/mkversion
  78. MV        ?= $(BINDIR)/mv
  79. RM        ?= $(BINDIR)/rm
  80. SED        ?= $(BINDIR)/sed
  81. TEST            ?= $(BINDIR)/test
  82. TOUCH        ?= $(BINDIR)/touch
  83. UPDATE        ?= $(BINDIR)/update
  84.  
  85. #
  86. # Several variables (such as where to install) are set based on the
  87. # TYPE variable.  Of course, any of these variables can be overridden
  88. # by explicit assignments.
  89. #
  90. TYPE        ?= unknown
  91. #if !empty(TYPE:Msprite)
  92. INSTALLDIR    ?= /sprite/cmds
  93. INSTALLMAN    ?= /sprite/man/cmds
  94. #elif !empty(TYPE:Mx)
  95. INSTALLDIR    ?= /X/cmds
  96. INSTALLMAN    ?= /X/man/cmds
  97. #elif !empty(TYPE:MX11R3)
  98. INSTALLDIR    ?= /mic/X11R3/cmds
  99. INSTALLMAN    ?= /mic/X11R3/man/cmds
  100. #elif !empty(TYPE:Mlocal)
  101. INSTALLDIR    ?= /local/cmds
  102. INSTALLMAN    ?= /local/man/cmds
  103. #elif !empty(TYPE:MX11R4)
  104. INSTALLDIR    ?= /X11/R4/cmds
  105. INSTALLMAN    ?= /X11/R4/man/cmds
  106. #elif !empty(TYPE:Memacs)
  107. INSTALLDIR    ?= /emacs/cmds
  108. INSTALLMAN    ?= /emacs/man/cmds
  109. #elif !empty(TYPE:Mdaemon)
  110. INSTALLDIR    ?= /sprite/daemons
  111. INSTALLMAN    ?= /sprite/man/daemons
  112. #elif !empty(TYPE:Madmin)
  113. INSTALLDIR    ?= /sprite/admin
  114. INSTALLMAN    ?= /sprite/man/admin
  115. #elif !empty(TYPE:Mpersonal)
  116. INSTALLDIR    ?= $(HOME)/cmds
  117. INSTALLMAN    ?= $(HOME)/man/cmds
  118. LOADFLAGS    += -L$(HOME)/lib/$(TM).md
  119. XCFLAGS        += -I$(HOME)/lib/include
  120. .PATH.h        : $(HOME)/lib/include
  121. #ifndef        USERBACKUP
  122. NOBACKUP    =
  123. #endif
  124. #endif
  125. #ifdef INSTALLDIR
  126. TMINSTALLDIR    ?= $(INSTALLDIR).$(TM)
  127. #endif
  128.  
  129. #
  130. # Figure out what stuff we'll pass to sub-makes.
  131. #
  132. PASSVARS    = 'INSTALLDIR=$(INSTALLDIR)' 'TM=$(TM)' $(.MAKEFLAGS)
  133. #ifdef        XCFLAGS
  134. PASSVARS    += 'XCFLAGS=$(XCFLAGS)'
  135. #endif
  136. #ifdef        XAFLAGS
  137. PASSVARS    += 'XAFLAGS=$(XAFLAGS)'
  138. #endif
  139. #ifdef        NOBACKUP
  140. PASSVARS    += 'NOBACKUP=$(NOBACKUP)'
  141. #endif
  142. #ifdef        BACKUPAGE
  143. PASSVARS    += 'BACKUPAGE=$(BACKUPAGE)'
  144. #endif
  145.  
  146. #
  147. # Flags. These are ones that are needed by *all* programs. Any other
  148. # ones should be added with the += operator in the command-specific makefile.
  149. # The FLAGS variables are defined with the += operator in case this file
  150. # is included after the main makefile has already defined them...
  151. #
  152.  
  153. #include    <tm.mk>
  154. CTFLAGS        ?= -wtd
  155. INSTALLFLAGS    ?=
  156. INSTALLMANFLAGS    ?=
  157. LINTFLAGS    ?= -m$(TM)
  158. XCFLAGS        ?=
  159. LOADFLAGS    ?=
  160. XAFLAGS        ?=
  161. #
  162. # The .INCLUDES variable already includes directories that should be
  163. # used by cc and other programs by default.  Remove them, just so that
  164. # the output looks cleaner.
  165. #
  166. # The dec compiler doesn't include /sprite/lib/include, so we must leave
  167. # the path as is when TM=ds3100.  
  168. #
  169.  
  170. #include <debugflags.mk>
  171.  
  172. #if !empty(TM:Mds3100) || !empty(TM:Mds5000)
  173. CFLAGS        += $(GFLAG) $(OFLAG) $(TMCFLAGS) $(XCFLAGS) -I.
  174. #elif !empty(TM:Mspur)
  175. CFLAGS        += $(GFLAG) $(TMCFLAGS) $(XCFLAGS) -I.
  176. #else
  177. CFLAGS        += $(GFLAG) $(OFLAG) $(TMCFLAGS) $(XCFLAGS) -I.
  178. #endif
  179. CFLAGS        += $(.INCLUDES:S|^-I/sprite/lib/include$||g:S|^-I/sprite/lib/include/$(TM).md$||g)
  180. #if empty(TM:Mds3100) && empty(TM:Mds5000)
  181. AFLAGS        += $(TMAFLAGS) $(XAFLAGS)
  182. #else
  183. CFLAGS        += -I/sprite/lib/include -I/sprite/lib/include/$(TM).md
  184. AFLAGS        += $(.INCLUDES)
  185. #endif
  186.  
  187. #
  188. # Transformation rules: these have special features to place .o files
  189. # in md subdirectories, run preprocessor over .s files, and generate
  190. # .po files for profiling.
  191. #
  192.  
  193. .SUFFIXES    : .po
  194.  
  195. .c.o        :
  196.     $(RM) -f $(.TARGET)
  197.     $(CC) $(CFLAGS) -c $(.IMPSRC) -o $(.TARGET)
  198. .c.po        :
  199.     $(RM) -f $(.TARGET)
  200.     $(CC) $(CFLAGS) -DPROFILE -c $(.IMPSRC) -o $(.TARGET)
  201. .cc.o        :
  202.     $(RM) -f $(.TARGET)
  203.     $(CPLUSPLUS) $(CFLAGS) -c $(.IMPSRC) -o $(.TARGET)
  204. .cc.po        :
  205.     $(RM) -f $(.TARGET)
  206.     $(CPLUSPLUS) $(CFLAGS) -DPROFILE -c $(.IMPSRC) -o $(.TARGET)
  207. .s.po .s.o    :
  208. #if empty(TM:Mds3100) && empty(TM:Mds5000)
  209.     $(CPP) $(CFLAGS:M-[IDU]*) -m$(TM) -D$(TM) -D_ASM $(.IMPSRC) > $(.PREFIX).pp
  210.     $(AS) -o $(.TARGET) $(AFLAGS) $(.PREFIX).pp
  211.     $(RM) -f $(.PREFIX).pp
  212. #else
  213.     $(RM) -f $(.TARGET)
  214.     $(AS) $(AFLAGS) $(.IMPSRC) -o $(.TARGET)
  215. #endif
  216.  
  217. #
  218. # The following targets are .USE rules for creating things.
  219. #
  220.  
  221. #
  222. # MAKECMD usage:
  223. #    program : <objects> <libraries> MAKECMD
  224. #
  225. # Creates and links in the file version.o as well. Also makes program depend
  226. # on the state of the C library.
  227. #
  228. # Using .ALLSRC constrains the local.mk, in that additions to LIBS
  229. # must come before the system makefile(s).  The advantage (or at least
  230. # an advantage) is that it filters out duplicate .o files that would
  231. # appear in the OBJS list.  These duplicates can appear if the command
  232. # generates source files on-the-fly: the local.mk typically has a
  233. # line like OBJS += foo.o, and if mkmf is run after foo.c is created,
  234. # foo.o will appear twice.  Also, using .ALLSRC lets pmake generate
  235. # a command based on knowledge of the search path, rather than
  236. # relying on the particular tool (e.g., cc or ld) to do the search
  237. # path processing.
  238. #
  239. MAKECMD        : .USE -lc
  240.     @echo "Generating date stamp"
  241.     @$(RM) -f version.h
  242.     @$(MKVERSION) > version.h
  243.     $(RM) -f $(TM).md/version.o
  244.     $(CC) $(CFLAGS) -c -o $(TM).md/version.o $(MISCLIBDIR)/version.c
  245.     $(RM) -f $(.TARGET)
  246.     $(CC) $(CFLAGS) -o $(.TARGET) $(LOADFLAGS) $(TM).md/version.o $(.ALLSRC:N-lc) 
  247. #if !empty(TM:Mspur) && empty(MACHINE:Mspur)
  248.     $(XLD) $(.TARGET)
  249. #endif
  250.  
  251. #
  252. # MAKECMDNOVERS usage:
  253. #    <program> : <objects> <libraries> MAKECMDNOVERS
  254. #
  255. # Similar to MAKECMD, except it doesn't create the version.[ho] files.
  256. #
  257. MAKECMDNOVERS    :  .USE -lc
  258.     $(RM) -f $(.TARGET)
  259.     $(CC) $(CFLAGS) -o $(.TARGET) $(LOADFLAGS) $(.ALLSRC:N-lc)
  260. #if !empty(TM:Mspur) && empty(MACHINE:Mspur)
  261.     $(XLD) $(.TARGET)
  262. #endif
  263.  
  264. #
  265. # MAKEINSTALL usage:
  266. #    install :: <dependencies> MAKEINSTALL
  267. #
  268. # The program is installed in $(TMINSTALLDIR) and backed-up to
  269. # $(TMINSTALLDIR).old
  270. #
  271. #ifndef NOBACKUP
  272. BACKUP        = -b $(TMINSTALLDIR).old
  273. #ifdef BACKUPAGE
  274. BACKUP += -B $(BACKUPAGE)
  275. #endif
  276. #else
  277. BACKUP        =
  278. #endif  NOBACKUP
  279.  
  280. #if !empty(TM:Mspur)
  281. # use a separate install script that doesn't strip
  282. # note that XLD has already been run
  283. MAKEINSTALL    : .USE
  284.     $(UPDATE) -m 775 $(BACKUP) $(INSTALLFLAGS) $(TM).md/$(NAME) \
  285.         $(TMINSTALLDIR)/$(NAME)
  286. #else
  287. MAKEINSTALL    : .USE
  288.     $(UPDATE) -m 775 -s $(BACKUP) $(INSTALLFLAGS) $(TM).md/$(NAME) \
  289.         $(TMINSTALLDIR)/$(NAME)
  290. #endif
  291.  
  292. #
  293. # MAKELINT usage:
  294. #    <fluff-file> : <sources to be linted> MAKELINT
  295. #
  296. # <fluff-file> is the place to store the output from the lint.
  297. #
  298. MAKELINT    : .USE
  299.     $(RM) -f $(.TARGET)
  300.     $(LINT) $(LINTFLAGS) $(CFLAGS:M-[IDU]*) $(.ALLSRC) > $(.TARGET) 2>&1
  301.  
  302. #
  303. # MAKEDEPEND usage:
  304. #    <dependency-file> : <sources> MAKEDEPEND
  305. #
  306. # Generate dependency file suitable for inclusion in future makes.
  307.  
  308. MAKEDEPEND    : .USE
  309.     @$(TOUCH) $(DEPFILE)
  310. #if empty(TM:Mds3100) && empty(TM:Mds5000)
  311.     $(MAKEDEPEND) $(CFLAGS:M-[ID]*) -m $(TM) -w60 -f $(DEPFILE) $(.ALLSRC)
  312. #else
  313.     $(MAKEDEPEND) $(CFLAGS:M-[ID]*:S|^-I/sprite/lib/include$||g:S|^-I/sprite/lib/include/$(TM).md$||g) -m $(TM) -w60 -f $(DEPFILE) $(.ALLSRC)
  314. #endif
  315.     @$(MV) -f $(DEPFILE) $(DEPFILE).tmp
  316.     @$(SED) -e '/^#/!s|^.|$(TM).md/&|' <$(DEPFILE).tmp > $(DEPFILE)
  317.     @$(RM) -f $(DEPFILE).tmp
  318.  
  319. #if !defined(no_targets) && defined(NAME)
  320. #
  321. # We should define the main targets (make, make install, etc.).  See the
  322. # mkmf man page for details on what these do.
  323. #
  324. LIBS            ?=
  325.  
  326. default            :: $(TM).md/$(NAME)
  327. #if defined(use_version)
  328. $(TM).md/$(NAME)    : $(OBJS) $(LIBS) MAKECMD
  329. #else
  330. $(TM).md/$(NAME)    : $(OBJS) $(LIBS) MAKECMDNOVERS
  331. #endif
  332.  
  333.  
  334. clean            :: .NOEXPORT tidy 
  335.     $(RM) -f $(TM).md/$(NAME) $(TM).md/$(NAME)$(PROFSUFFIX)
  336.  
  337. tidy            :: .NOEXPORT
  338. #if defined(CLEANOBJS) && !empty(CLEANOBJS)
  339.     $(RM) -f $(CLEANOBJS) $(CLEANOBJS:M*.o:S/.o$/.po/g)
  340. #endif
  341.     $(RM) -f y.tab.c lex.yy.c core \
  342.             $(TM).md/lint \
  343.         a.out *~ $(TM).md/*~ gmon.out mon.out
  344.  
  345. DEPFILE = $(TM).md/dependencies.mk
  346.  
  347. depend            : $(DEPFILE)
  348. $(DEPFILE)        ! $(SRCS:M*.c) $(SRCS:M*.s) $(SRCS:M*.cc) MAKEDEPEND
  349.  
  350.  
  351. #
  352. # For "install", a couple of tricks.  First, allow local.mk to disable
  353. # by setting no_install.  Second, use :: instead of : so that local.mk
  354. # can augment install with additional stuff.  Third, don't install if
  355. # TMINSTALLDIR isn't set.
  356. #
  357. #ifndef no_install
  358. #ifdef TMINSTALLDIR
  359. install            :: $(TM).md/$(NAME) installman MAKEINSTALL
  360. #else
  361. install            :: .SILENT
  362.     echo "Can't install $(NAME):  no install directory defined"
  363. #endif TMINSTALLDIR
  364. #endif no_install
  365.  
  366.  
  367. #if empty(MANPAGES)
  368. installman        :: .SILENT
  369.     echo "There's no man page for $(NAME).  Please write one."
  370. #elif !empty(MANPAGES:MNONE)
  371. installman        ::
  372.  
  373. #elif defined(INSTALLMAN)
  374. installman        :: .SILENT $(MANPAGES)
  375.     $(UPDATE) -m 444 -l $(INSTALLMANFLAGS) $(MANPAGES) $(INSTALLMAN)
  376. #else
  377. installman        :: .SILENT
  378.     echo "Can't install man page(s): no install directory defined"
  379. #endif
  380.  
  381.  
  382. lint            : $(TM).md/lint
  383. $(TM).md/lint        : $(SRCS:M*.c) $(LIBS:M-l*) MAKELINT
  384.  
  385.  
  386. mkmf            :: .SILENT
  387.     mkmf
  388.  
  389.  
  390. newtm            :: .SILENT
  391.     if $(TEST) -d $(TM).md; then
  392.         true
  393.     else
  394.         mkdir $(TM).md;
  395.         chmod 775 $(TM).md;
  396.         mkmf -m$(TM)
  397.     fi
  398.  
  399.  
  400. profile            : $(TM).md/$(NAME)$(PROFSUFFIX)
  401. #if empty(TM:Mds3100) && empty(TM:Mds5000)
  402. PROFFLAG = -pg
  403. #else
  404. PROFFLAG = -p
  405. #endif
  406. $(TM).md/$(NAME)$(PROFSUFFIX)    : $(OBJS:S/.o$/.po/g) $(LIBS:S/.a$/_p.a/g)
  407.     $(RM) -f $(.TARGET)
  408.     $(CC) $(CFLAGS) $(PROFFLAG) -o $(.TARGET) $(.ALLSRC)
  409.  
  410.  
  411. tags            :: $(SRCS:M*.c) $(HDRS)
  412.     $(CTAGS) $(CTFLAGS) $(SRCS:M*.c) $(HDRS)
  413.  
  414. TAGS            :: $(SRCS:M*.[ch]) $(HDRS)
  415.     $(ETAGS) $(SRCS:M*.[ch])
  416.  
  417. version.h        :
  418.     $(RM) -f version.h
  419.     $(MKVERSION) > version.h
  420.  
  421. DISTFILES    ?=
  422.  
  423. dist        !
  424. #if defined(DISTDIR) && !empty(DISTDIR)
  425.     for i in Makefile local.mk sprite dist \
  426.         $(TM).md/md.mk $(SRCS) $(HDRS) $(DISTFILES)
  427.     do
  428.     if $(TEST) -e $${i}; then
  429.         $(UPDATE)  $${i} $(DISTDIR)/$${i} ;else true; fi
  430.     done
  431. #endif
  432.  
  433. #include    <all.mk>
  434.  
  435. #endif no_targets && NAME
  436.  
  437. .MAKEFLAGS    : -C        # No compatibility needed
  438.  
  439. #include    <rdist.mk>
  440.